﻿using FreeRedis;
using sixgod.Service.Dictionary;

namespace sixgod.personnel.HostService
{
    /// <summary>
    /// 系统必要数据缓存初始化
    /// </summary>
    public class CacheInitService:IHostedService
    {
        private RedisClient _redisClient;
        private IDictionaryService _dictionaryService;
        /// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary>
        public CacheInitService(RedisClient redisClient, IDictionaryService dictionaryService)
        {
            _redisClient = redisClient;
            _dictionaryService = dictionaryService;
        }

        /// <summary>
        /// Triggered when the application host is ready to start the service.
        /// </summary>
        /// <param name="cancellationToken">Indicates that the start process has been aborted.</param>
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            await _dictionaryService.Init();
        }

        /// <summary>
        /// Triggered when the application host is performing a graceful shutdown.
        /// </summary>
        /// <param name="cancellationToken">Indicates that the shutdown process should no longer be graceful.</param>
        public Task StopAsync(CancellationToken cancellationToken)
        {
            return null;
        }
    }
}
